#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int numEquivDominoPairs(vector<vector<int>>& dominoes) {
        int n = dominoes.size(), res = 0;
        unordered_map<int, vector<pair<int, int>>> hash;
        for (int i = 0; i < n; i++)
        {
            int x = dominoes[i][0], y = dominoes[i][1];
            int sum = x + y;
            for (auto& [a, b] : hash[sum])
            {
                if (x == a || x == b)
                    ++res;
            }
            hash[sum].push_back({ x, y });
        }
        return res;
    }
};